package com.dingwen.treasure.tkmybatis.service.impl;

import com.dingwen.treasure.tkmybatis.dao.TreasureFileMapper;
import com.dingwen.treasure.tkmybatis.entity.TreasureFile;
import com.dingwen.treasure.tkmybatis.service.TreasureFileService;
import com.dingwen.treasure.tkmybatis.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;

/**
 * 　TreasureFileServiceImpl
 * 　@author dingwen
 * 　@date 2022/7/4
 */
@Service
public class TreasureFileServiceImpl extends BaseServiceImpl<TreasureFile, TreasureFileMapper> implements TreasureFileService {
    /**
     * 保存文件上传信息
     *
     * @param fileName      文件名称
     * @param multipartFile 文件
     */
    @Override
    public void save(String fileName, String url,MultipartFile multipartFile) {
        TreasureFile treasure = TreasureFile.builder()
                .fileName(fileName)
                .url(url)
                .originalFileName(multipartFile.getOriginalFilename())
                .fileSize(multipartFile.getSize())
                .fileType(multipartFile.getContentType())
                .createTime(LocalDateTime.now())
                .remark("视频文件分片上传本地服务器，基于nginx实现点播")
                //TODO 当前登录用户
                .createBy("treasure")
                .build();
        add(treasure);
    }
}
